<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>45. 正则方法exec</title>
</head>
<body>
   <main>后盾后盾人热饭撒六后盾人块腹后盾人肌啊后盾人螺蛳粉</main>
</body>
<script>
//regObj exec <====> stringObj match


let reg=/后盾人/g;
const main=document.querySelector('body main');
// console.log(main.innerHTML);
// console.log(main.innerHTML.match(reg)); //stringOjb 调用match
// console.log(reg.exec(main.innerHTML)); //regObj 调用exec
//二者结果差别不大
//match 无细节
//exec 有细节


//2. 可以利用exec 的lastIndex 做循环统计次数
let count=0;
while((res=reg.exec(main.innerHTML))){
    count++;
}
console.log(count);

</script>

</html>